﻿#ifndef __SS_WSPP_BASE_H__
#define __SS_WSPP_BASE_H__
#include "ssBaseDefine.h"
#include "tools/ssIDAlloter.h"
#include <map>
#include "ssWsppSession.h"

namespace StarSeeker
{

typedef websocketpp::lib::shared_ptr<websocketpp::lib::thread> thread_ptr;

class ssWsppBase
{
public:
	ssWsppBase();
	virtual~ssWsppBase();
	//参数配置
	void InitParam(u32 sessionCount, u32 threadCount = 1, bool timeCheck=false);
	//处理网络消息
	virtual void OnSessionMessage(u32 sessionID, const char* ip, u32 msgID, char* data, ssNetMsgHead* head);
	//连接断开后
	virtual void OnSessionClose(u32 sessionID);
	//连接建立后
	virtual void OnNewSession(u32 sessionID);

protected:
	websocketpp::lib::asio::io_service*	m_ioService;
	std::vector<thread_ptr>				m_threads;
	ssCumulationID<u32>					m_idAlloter;
	std::map<u32, ssWsppSession*>		m_sessionId;
	std::map<void*, ssWsppSession*>		m_sessionHdl;
	u32									m_sessionCount;		//连接对象最大数量
	u32									m_threadCount;		//线程数量
	bool								m_timeCheck;		//收包间隔检测
};

}
#endif
